package main

import (
	"fmt"
	"github.com/meilisearch/meilisearch-go"
	"os"
)

func main() {
	client := meilisearch.NewClient(meilisearch.ClientConfig{
		Host:   "http://119.91.228.85:6017/",
		APIKey: "HmPEKZhcoANzRt3DTPhRQVRxPEVZw7m2TymKwKhs_6xdnky",
	})

	//An index is where the documents are stored.
	index := client.Index("movies")

	//If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
	documents := []map[string]interface{}{
		{
			"id":          7,
			"title":       "The Shawshank Redemption",
			"title_cn":    "肖申克的救赎",
			"year":        1994,
			"genre":       []string{"Drama"},
			"genre_cn":    []string{"剧情"},
			"director":    "Frank Darabont",
			"director_cn": "弗兰克·德拉邦特",
			"actors":      []string{"Tim Robbins", "Morgan Freeman", "Bob Gunton"},
			"actors_cn":   []string{"蒂姆·罗宾斯", "摩根·弗里曼", "鲍勃·冈顿"},
			"plot":        "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.",
			"plot_cn":     "两个被囚禁的男人在多年的时间里建立了联系，通过共同的善行找到了安慰和最终的救赎。",
			"image":       "https://www.imdb.com/title/tt0111161/mediaviewer/rm2698455552/",
		},
	}
	task, err := index.AddDocuments(documents)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(task.TaskUID)
}
